//
//  CZDiscoverSearchView.swift
//  WHWeiBo01
//
//  Created by whitcast on 16/7/12.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZDiscoverSearchView: UIView, UITextFieldDelegate {

    @IBOutlet weak var textFieldRight: NSLayoutConstraint!
    @IBOutlet weak var cancelButton: UIButton!
    @IBOutlet weak var textField: UITextField!
    //  加载xib
    class func searchView() -> CZDiscoverSearchView {
        
       return UINib(nibName: "CZDiscoverSearchView", bundle: nil).instantiateWithOwner(nil, options: nil).last! as! CZDiscoverSearchView
        
        
    }
    @IBAction func cancelAction(sender: AnyObject) {
        //  取消第一响应者
//        self.endEditing(true)
        textField.resignFirstResponder()
        textFieldRight.constant = 0
        
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }

        
    }
    
    // MARK: -- UITextFieldDelegate 代理
    
    
    func textFieldDidBeginEditing(textField: UITextField) {
        
        textFieldRight.constant = cancelButton.width
        
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }
        
        
    }
    

}
